import {defaultStyle} from "@/svgutil/default-style";
import * as Dt from '@/svgutil/draw-type';
import {findObjectValue} from "@/svgutil/comm-method";

export const defineData = function (values) {

    return {
        translate: [0.5, 0.5],
        style: {...defaultStyle},
        children: [
            testRect(),
            testTable(values),
        ]
    }
}

function testRect() {
    let x = 400;
    let y = 200;
    let w = 100;
    let h = 100;
    return Dt.rect(x,y,w,h).setStyle({fill: 'red'});
    //let rect = new Dt.Rect(x, y, w, h).setStyle({fill: 'red',stroke: 'none'});
    //return rect;
}
function testTable(values) {
    let col = [
        {
            label: '标题1',
            children: [
                {
                    label: '列1',
                    prop: 'col1',
                },
                {
                    label: '列2',
                    prop: 'col2',
                },
                {
                    label: '列3',
                    prop: 'col3',
                }
            ]
        },
        {
            label: '列4',
            prop: 'col4',
        }
    ];
    let data = [
        {col1: '{{P001}}[v]',col2: '{{P002}}[v]',col3: 3, col4: 4,col5: 'KG'},
        {col1: 11,col2: 12,col3: 13, col4: 14,col5: 15},
    ];
    let table = Dt.table(600, 200, 300, 100).setHeaderHeight(40);
    table.setColumn(col)
        .setData(data);
    table.cellStyle = (cell,colIndex,row) => {
        let tagValue = findObjectValue(row[cell.prop], values);
        if(tagValue && typeof tagValue === 'object' && tagValue.w === 1){
            return {
                tableStyle: {
                    fill: 'red',
                },
                fontStyle: {
                    fill: '#fff',
                }
            }
        }
    }
    return table;
}